﻿using System.Net;
using System.ServiceModel.Web;

namespace PeoplesJukebox.Services.Helpers
{
    /// <summary>
    /// Helper for REST-style arguments
    /// </summary>
    public static class ArgumentHelper
    {
        /// <summary>
        /// Returns an integer ID from a string
        /// </summary>
        /// <remarks>
        /// Sets the HTTP status code to "bad request" if the given
        /// ID is not a valid integer value
        /// </remarks>
        /// <param name="textId">String ID</param>
        /// <returns>Integer ID</returns>
        public static int GetId(string textId)
        {
            int id = -1;
            if (!int.TryParse(textId, out id))
            {
                WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
            }
            return id;
        }
    }
}